/***************************************************
> Copyright (C) 2024 ==RXX== All rights reserved.
> File Name: 1.c
> Author: rxx
> Mail:2909017383@qq.com 
> Created Time: 2024年12月03日 星期二 11时27分58秒
***************************************************/
#include "adminxx.h"
#include "userxx.h"

//创建头节点
ADM *inputAdmin(ADM *admhead)
{
	admhead = (ADM*)malloc(sizeof(ADM));
	memset(admhead,0,sizeof(ADM));
	if(admhead == NULL)
	{
		perror("malloc");
		exit(1);
	}
	return admhead;
}
//管理员菜单
void menu2()
{
	printf("########################################################\n");
	printf("\t\t\t1 修改密码\n");
	printf("\t\t\t2 查看用户信息\n");
	printf("\t\t\t3 修改机器状态\n");
	printf("\t\t\t4 退出\n");
	printf("########################################################\n");
}
//登陆
ADM* adminLogOn(ADM *admhead,STU* head)
{
	strcpy(admhead->user, "12345678");
	strcpy(admhead->password ,"qwertyui");
	char auser[20];
	char apassword[20];
	printf("输入user：");
	scanf("%s",auser);//输入用户和密码
	printf("输入password：");
	scanf("%s",apassword);
	//输入数据
	if( strcmp(admhead->user,auser) == 0 && 
			strcmp(admhead->password,apassword) == 0 )
	{
		printf("登陆成功！\n");
		int num3 = 0;
		int flag3 = 0;
		char value[20];	
		//int washing[5] = {0 , 1, 0 , 1, 0};
		while(flag3 == 0)
		{
			menu2();
			printf("输入要执行的内容编号：\n");
			scanf("%d",&num3);
			switch(num3)
			{
				case 1:
					printf("输入管理员的用户名：\n");
					scanf("%s",value);
					changePassword(admhead,value);	//修改密码
					break;
				case 2:	
					// show head
					output(head);
					break;
				case 3:
					machineState(washing,5);
					break;
				default:
					//	printf("");//打印的用户及其密码
					flag3 = 1;
					break;
			}
		}
	}
	//对比不成功
	else
	{
		printf("登陆失败！\n");
	}
	return admhead;
}

//修改节点的值
ADM *changePassword(ADM *admhead,char *value)
{
	char str1[20] ;
	if( (strcmp(admhead->user ,value)) == 0)
	{
		printf("输入要修改的密码：");
		scanf("%s",str1);
		strcpy(admhead->password,str1);
		printf("修改成功！\n");
		return 0;
	}
	else
	{
		printf("没有该管理员！\n");
	}
	return admhead;
}
